﻿namespace UtilZ.Dotnet.Ex.ValueDescription
{
    /// <summary>
    /// 值描述管理类
    /// </summary>
    public class ValueDescriptionManager
    {
        private readonly static ValueDescriptionManagerCore _default = null;
        static ValueDescriptionManager()
        {
            _default = new ValueDescriptionManagerCore();
        }



        /// <summary>
        /// 注册常量或枚举值描述
        /// </summary>
        /// <typeparam name="TValueType">值类型</typeparam>
        /// <typeparam name="TObject">目标类型</typeparam>
        public static void Registe<TValueType, TObject>()
        {
            _default.Registe<TValueType, TObject>();
        }

        /// <summary>
        /// 注册描述组
        /// </summary>
        /// <param name="group">值描述组</param>
        public static void Registe(IValueDescriptionGroup group)
        {
            _default.Registe(group);
        }





        /// <summary>
        /// 尝试根据类型获取值描述组,存在返回true,不存在返回false
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <param name="group">值名称映射字典集合</param>
        /// <returns>存在返回true,不存在返回false</returns>
        public static bool TryGetValueDescriptionGroup<T>(out IValueDescriptionGroup group)
        {
            return _default.TryGetValueDescriptionGroup<T>(out group);
        }

        /// <summary>
        /// 根据组标识获取值描述组,存在返回true,不存在返回false
        /// </summary>
        /// <param name="groupId">组标识</param>
        /// <param name="group">值名称映射字典集合</param>
        /// <returns>存在返回true,不存在返回false</returns>
        public static bool TryGetValueDescriptionGroup(object groupId, out IValueDescriptionGroup group)
        {
            return _default.TryGetValueDescriptionGroup(groupId, out group);
        }






        /// <summary>
        /// 根据类型移除值描述组[移除成功返回true,否则返回false]
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <returns>[移除成功返回true,否则返回false]</returns>
        public static bool Remove<T>()
        {
            return _default.Remove<T>();
        }

        /// <summary>
        /// 根据组标识移除值描述组[移除成功返回true,否则返回false]
        /// </summary>
        /// <param name="groupId">组标识</param>
        /// <returns>[移除成功返回true,否则返回false]</returns>
        public static bool RemoveById(object groupId)
        {
            return _default.RemoveById(groupId);
        }





        /// <summary>
        /// 清空值描述组
        /// </summary>
        public static void Clear()
        {
            _default.Clear();
        }






        /// <summary>
        /// 清空指定类型值描述组
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public static void Clear<T>()
        {
            _default.Clear<T>();
        }

        /// <summary>
        /// 清空指定组标识值描述组
        /// </summary>
        /// <param name="groupId">组标识</param>
        public static void Clear(object groupId)
        {
            _default.Clear(groupId);
        }






        /// <summary>
        /// 根据组标识和值获取值名称(获取成功返回值名称;失败抛出ArgumentException异常)
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <param name="value">值</param>
        /// <returns>值名称</returns>
        public static string GetNameByValue<T>(object value)
        {
            return _default.GetNameByValue<T>(value);
        }

        /// <summary>
        /// 根据组标识和值获取值名称(获取成功返回值名称;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="groupId">组标识</param>
        /// <param name="value">值</param>
        /// <returns>值名称</returns>
        public static string GetNameByValue(object groupId, object value)
        {
            return _default.GetNameByValue(groupId, value);
        }





        /// <summary>
        /// 尝试根据组标识和值获取值名称(获取成功返回true;失败返回false)
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <param name="value">值</param>
        /// <param name="name">值名称</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public static bool TryGetNameByValue<T>(object value, out string name)
        {
            return _default.TryGetNameByValue<T>(value, out name);
        }

        /// <summary>
        /// 尝试根据组标识和值获取值名称(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="groupId">组标识</param>
        /// <param name="value">值</param>
        /// <param name="name">值名称</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public static bool TryGetNameByValue(object groupId, object value, out string name)
        {
            return _default.TryGetNameByValue(groupId, value, out name);
        }






        /// <summary>
        /// 根据值获取值描述(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <param name="value">值</param>
        /// <returns>值描述</returns>
        public static string GetDescriptionByValue<T>(object value)
        {
            return _default.GetDescriptionByValue<T>(value);
        }

        /// <summary>
        /// 根据组标识和值获取值描述(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="groupId">组标识</param>
        /// <param name="value">值</param>
        /// <returns>值描述</returns>
        public static string GetDescriptionByValue(object groupId, object value)
        {
            return _default.GetDescriptionByValue(groupId, value);
        }

        /// <summary>
        /// 尝试根据值获取值描述(获取成功返回true;失败返回false)
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <param name="value">值</param>
        /// <param name="des">值描述</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public static bool TryGetDescriptionByValue<T>(object value, out string des)
        {
            return _default.TryGetDescriptionByValue<T>(value, out des);
        }

        /// <summary>
        /// 尝试根据组标识和值获取值描述(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="groupId">组标识</param>
        /// <param name="value">值</param>
        /// <param name="des">值描述</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public static bool TryGetDescriptionByValue(object groupId, object value, out string des)
        {
            return _default.TryGetDescriptionByValue(groupId, value, out des);
        }






        /// <summary>
        /// 根据名称获取值(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <param name="name">名称</param>
        /// <returns>值</returns>
        public static object GerValueByName<T>(string name)
        {
            return _default.GetValueByName<T>(name);
        }

        /// <summary>
        /// 根据名称获取值(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="groupId">组标识</param>
        /// <param name="name">名称</param>
        /// <returns>值</returns>
        public static object GerValueByName(object groupId, string name)
        {
            return _default.GetValueByName(groupId, name);
        }

        /// <summary>
        /// 根据名称获取值(获取成功返回true;失败返回false)
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <param name="name">名称</param>
        /// <param name="value">值</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public static bool TryGerValueByName<T>(string name, out object value)
        {
            return _default.TryGetValueByName<T>(name, out value);
        }

        /// <summary>
        /// 根据名称获取值(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="groupId">组标识</param>
        /// <param name="name">名称</param>
        /// <param name="value">值</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public static bool TryGerValueByName(object groupId, string name, out object value)
        {
            return _default.TryGetValueByName(groupId, name, out value);
        }







        /// <summary>
        /// 获取指定类型值数组
        /// </summary>
        /// <param name="groupId">组标识</param>
        /// <typeparam name="T">目标类型</typeparam>
        /// <returns>类型所有定义常量值数组</returns>
        public static T[] GetValues<T>(object groupId)
        {
            return _default.GetValues<T>(groupId);
        }

        /// <summary>
        /// 获取指定类型值数组
        /// </summary>
        /// <param name="groupId">组标识</param>
        /// <returns>类型所有定义常量值数组</returns>
        public static object[] GetValues(object groupId)
        {
            return _default.GetValues(groupId);
        }






        /// <summary>
        /// 获取指定类型名称数组
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <returns>类型所有定义常量值数组</returns>
        public static string[] GetNames<T>()
        {
            return _default.GetNames<T>();
        }

        /// <summary>
        /// 获取指定类型名称数组
        /// </summary>
        /// <param name="groupId">组标识</param>
        /// <returns>类型所有定义常量值数组</returns>
        public static string[] GetNames(object groupId)
        {
            return _default.GetNames(groupId);
        }
    }
}
